﻿using MediatR;
using SlaughterItem.Common.Domains.Manages;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week01.BusinessCommends
{
    /// <summary>
    /// 获取企业信息
    /// </summary>
    public class BusinessShowHandler : IRequestHandler<BusinessShowCommand, Result>
    {
        public IBaseRepositoryGet<Business> BusinessRepositoryGet;

        public BusinessShowHandler(IBaseRepositoryGet<Business> businessRepositoryGet)
        {
            BusinessRepositoryGet = businessRepositoryGet;
        }

        public async Task<Result> Handle(BusinessShowCommand request, CancellationToken cancellationToken)
        {
            var result=new Result() { Code=(int)CommonErrorCode.Search};
            var list = BusinessRepositoryGet.GetAll().ToList();
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCode.Success;
                return result;
            }
            else
            { 
                return result;
            }
        }
    }
}
